package com.example.designpattern;

import android.graphics.Bitmap;

/**
 * Author 方隽琦
 * Date 2020/12/28
 * Description
 */
public class DoubleCache implements ImageCache{
    ImageCache mMemoryCache = new MemoryCache();
    ImageCache mDiskCache = new DiskCache();
    //先从内存缓存中获取图片，如果没有则从SD卡缓存中获取图片
    @Override
    public Bitmap get(String url){

        Bitmap bitmap =  mMemoryCache.get(url);
        if (bitmap == null){
            bitmap = mDiskCache.get(url);
        }
        return bitmap;
    }
    //将图片缓存到内存和SD卡中
    public void put(String url,Bitmap bitmap){
        mMemoryCache.put(url, bitmap);
        mDiskCache.put(url, bitmap);
    }
}
